package it.polimi.digitalstate.dto;

import java.util.Date;

import javax.validation.constraints.*;

import org.hibernate.validator.constraints.*;

public class CitizenDTO implements IDataTransferObject{
	
	private Integer id;
	@Size(min=5, message="Too short ecode, check to had type it correctly.")
	private String ecode;
	@NotEmpty(message="This field is required")
	private String name;
	@NotEmpty(message="This field is required")
	private String surname;
	private Date dob;
	
	public CitizenDTO(){
		
	}
	public CitizenDTO(String ecode,String name, String surname, Date dob){
		this.ecode=ecode;
		this.name=name;
		this.surname=surname;
		this.dob=dob;
	}
	
	public CitizenDTO(int id, String ecode,String name, String surname, Date dob){
		this(ecode,name, surname, dob);
		this.id=new Integer(id);	//boxing
	}
	
	public String getEcode() {
		return ecode;
	}
	
	public void setEcode(String ecode) {
		this.ecode = ecode;
	}
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public String getSurname() {
		return surname;
	}
	
	public void setSurname(String surname) {
		this.surname = surname;
	}
	
	public Date getDob() {
		return dob;
	}
	
	public void setDob(Date dob) {
		this.dob = dob;
	}
	public String getFullName(){
		return name + " " + surname;
	}
	public int getID(){
		if(id==null){
			return -1;
		}
		return id.intValue(); //unboxing
		
	}
	
	@Override
	public boolean equals(Object obj) {
	       if (!(obj instanceof CitizenDTO))
	            return false;
	        if (obj == this)
	            return true;
	        if (((CitizenDTO) obj).getID() == this.getID())
		        return true;
		    return false;
	}	
	public int hashCode() {
		return this.getID();
    }
}
